home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / HoweExample3.c < prev    next >
Text File  |  1990-08-07  |  2KB  |  108 lines

  1. /*
  2. * ⌐ Graeme Gerrard 1990
  3. * Faculty of Music, University of Melbourne
  4. * Parkville Victoria 3052 Australia.
  5. *
  6. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  7. * telephone: (613) 344 4127, Fax: (613) 344 5346
  8. */
  9.  
  10.  
  11. #include    "Music4C.h"
  12. #include    <math.h>
  13. #include    "ugens.h"
  14. #include    "orch.h"
  15.  
  16. #define    EXAMPLE3    1
  17. #define    MAXINS        5
  18.  
  19.  
  20.  
  21. static    double    *a;
  22. static    long    sampno;
  23. static    long    base;
  24. extern    Str255    theMess1;
  25.  
  26.  
  27. void initl()
  28. {
  29.     register long    j;
  30.     a = (double *)NewPtr(MAXINS * 29 * sizeof(double));
  31.     if ( a == 0L )
  32.         fprintf(stderr, "Not enough memory in initl\n");
  33.     for ( j = 0; j < MAXINS * 29; j++ )
  34.         *(a+j) = 0.0;
  35. }
  36.  
  37.  
  38. void setup()
  39. {
  40. /*
  41. * p4 = pitch (in 8ve.pc)
  42. * p5 = amp
  43. * p6 = initial centre freq of BP filter
  44. * p7 = final centre freq of BP filter
  45. *
  46. */
  47.     switch(instype) {
  48.         case EXAMPLE3:
  49.             if ( insno > MAXINS ) {
  50.                 sprintf((char *)theMess1, "Instrument number %d is out of range", insno);
  51.                 CtoPstr((char *)theMess1);
  52.                 OSError(theMess1, NIL, NIL );
  53.             }
  54.             base = ((insno-1) * 29);
  55.             *(a+base) = p[5] * 1000.0;
  56.             *(a+base+1) = pitch(p[4]);
  57.             *(a+base+2) = (int)(5000.0/cpspch(p[4]));
  58.             rsnset(0.0, 2500.0, 1.0, 0.0, (a+base+4));
  59.             *(a+base+9) = p[7] - p[6];
  60.             *(a+base+10) = period(p[3]);
  61.             *(a+base+11) = 0.0;
  62.             *(a+base+12) = p[6];
  63.             vrsset(*(a+base), 0.0, (a+base+13));
  64.             blnset(10.0, 0.0, (a+base+18));
  65.             evpset(0.025, 0.2, *(p+3), 0.2, 5, 5, (a+base+24));
  66.             
  67.             break;
  68.         default:
  69.             /*fprintf(stderr, "error in instrument type number, %d\n", instype);*/
  70.             ;
  71.     }
  72. }
  73.  
  74. void orch()
  75. {
  76.     register    double    x;
  77.     register    double    y;
  78.     register    double    sig;
  79.     register    double    z;
  80.     
  81.     switch(instype) {
  82.         case EXAMPLE3:
  83.             base = ((insno-1) * 29);
  84.             x = buzz(*(a+base), *(a+base+1), *(a+base+2), 1, (a+base+3));
  85.             x = reson(x, (a+base+4));
  86.             y = oscil1(*(a+base+9), *(a+base+10), 3, (a+base+11)) + *(a+base+12);
  87.             z = vreson(x, y, y * 0.1, 2560.0, 4, (a+base+13));
  88.             x = balnce(z, x, (a+18));
  89.  
  90.             sig = envlp(x, 5, 5, (a+base+24));
  91.             Mono(sig);
  92.             break;
  93.         default:
  94.             fprintf(stderr, "error in instrument type number, %d\n", instype);
  95.     }
  96. }
  97. void ter()
  98. {
  99.     /* just gets called at the end a note for clean up etc. */
  100. }
  101.  
  102. void final()
  103. {
  104. /* called at the end of the synth run.
  105. *  close any files etc. you haven't already closed here.
  106. */
  107. }
  108.